/*
 * Copyright (C) 2008 GeoScheduler Team, as stated on <http://www.geoscheduler.org/authors>.
 * 
 * This file is part of GeoScheduler.
 * 
 * GeoScheduler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GeoScheduler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with GeoScheduler. If not, see <http://www.gnu.org/licenses/>.
 */
package org.geoscheduler.commons.qbuilder;

/**
 * FIXME [lko] comment me!
 *
 * @author lko
 */
public abstract class AbstractSQLBuilder<T extends SQLBuilder<?>> implements SQLBuilder<T> {

	private StringBuilder bld;
	boolean delimiter;

	public AbstractSQLBuilder() {
		this(new StringBuilder());
	}

	public AbstractSQLBuilder(StringBuilder bld) {
		super();
		this.bld = bld;
	}

	protected String evalCurrent() {
		return bld.toString();
	}

	public String toString() {
		return bld.toString();
	}

	@SuppressWarnings("unchecked")
	protected T append(String value) {
		bld.append(value);
		return (T) this;
	}

	@SuppressWarnings("unchecked")
	public T raw(String value) {
		bld.append(value);
		return (T) this;

	}

	protected T delimiter() {
		return delimiter(false);
	}
	
	protected StringBuilder builder(){
		return bld;
	}

	@SuppressWarnings("unchecked")
	protected T delimiter(boolean force) {
		if (delimiter || force) {
			append(",");
		}
		delimiter = true;
		return (T) this;
	}

	protected boolean isDelimiter() {
		return this.delimiter;
	}

}
